import { connect } from 'react-redux'
import AdminForumCtrl from "../../components/admin/AdminForumCtrl/AdminForumCtrl.jsx"
import {getCourseList,searchCourse,sortCourseList,SORT,filterCourse,changePage,selectCourse,move,addCourse,delItem} from "../../actions/admin/admin_forum_actions.js"

// 竟然不能直接复用，这就是redux没学好就写的下场
const mapDispatchToProps = (dispatch) => {
    return {
        refresh : (filter) => {
            filter = filter || "ALL"
            dispatch(getCourseList())
        },
        init : () => {
            dispatch(getCourseList())
        },
        sort : (sortIdx,sortFlag) => {
            dispatch(sortCourseList(sortIdx,sortFlag))
        },
        search : (searchText) => {
            dispatch(searchCourse(searchText))
        },
        filter : (filterName) => {
            dispatch(filterCourse(filterName))
        },
        changePage : (page,limit) => {
            dispatch(changePage(page,limit))
        },
        selectCourse : (course) => {
            dispatch(selectCourse(course))
        },
        move : (direction,course) => {
            dispatch(move(direction,course))
        },
        addCourse : (course) => {
            dispatch(addCourse(course))
        },
        delItem : (item) => {
            dispatch(delItem(item))
        }
    }
}

const mapStateToProps = (state,ownProps) => {
    const {adminCourseTable} = state
    return {
        courses : adminCourseTable.courses,
        totalCount : adminCourseTable.cachedCourses.length,
        cachedCourses : adminCourseTable.cachedCourses,
        page : adminCourseTable.page,
        limit : adminCourseTable.limit,
        selectedCourses : adminCourseTable.selectedCourses
    }
}

const AdminForumCtrlContainer = connect(
    mapStateToProps,
    mapDispatchToProps
)(AdminForumCtrl)

exports.AdminForumCtrlContainer = AdminForumCtrlContainer